import 'package:aidou/widgets/video/buttonColumn.dart';
import 'package:aidou/widgets/video/comment.dart';
import 'package:aidou/widgets/video/player.dart';
import 'package:flutter/material.dart';
import 'package:safemap/safemap.dart';

class VideoPlayerPage extends StatefulWidget {
  final int index;
  final data;
  const VideoPlayerPage({
    Key? key,
    required this.index,
    required this.data,
  }) : super(key: key);

  @override
  _VideoPlayerPageState createState() => _VideoPlayerPageState();
}

class _VideoPlayerPageState extends State<VideoPlayerPage> {
  Map<int, bool> favoriteMap = {};

  @override
  Widget build(BuildContext context) {
    // 记录点赞
    bool isF = SafeMap(favoriteMap)[widget.index].boolean;
    // 右侧按钮
    Widget buttons = VideoButtonColumn(
      isFavorite: isF,
      onAvatar: () {},
      // 点赞
      onFavorite: () {
        setState(() {
          favoriteMap[widget.index] = !isF;
        });
      },
      // 评论
      onComment: () {
        showModalBottomSheet(
          backgroundColor: Colors.white.withOpacity(0),
          context: context,
          builder: (BuildContext context) => VideoCommentBottomSheet(),
        );
      },
      // 分享
      onShare: () {
        print('share');
      },
    );

    // video
    Widget currentVideo = Center(
      child: AspectRatio(
        aspectRatio: 16.0,
        // child: VideoPlayer(videoPlayerController),
      ),
    );
    return VideoPlayerItem(
      // 手势播放与自然播放都会产生暂停按钮状态变化，待处理
      hidePauseIcon: false,
      aspectRatio: 9 / 16.0,
      key: Key('$widget.index'),
      tag: '',
      bottomPadding: 16.0,
      userInfoWidget: VideoInfo(
        title: widget.data.title,
        nickName: widget.data.nickName,
        bottomPadding: 16.0,
      ),
      rightButtonColumn: buttons,
      video: currentVideo,
    );
  }
}
